package com.lhoverc.controller.admin;

import com.lhoverc.pojo.Result;
import com.lhoverc.pojo.VO.AnnouncementVO;
import com.lhoverc.pojo.dto.AnnouncementDto;
import com.lhoverc.pojo.entity.AnnouncementEntity;
import com.lhoverc.service.announcement.AnnouncementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: LiCheng
 * @CreateTime: 2025-04-19
 * @Description:
 * @Version: 1.0
 */
@RestController
@RequestMapping("/admin/announcement")
public class AdminAnnouncementController {

    @Autowired
    private AnnouncementService announcementService;

    /**
     * 查询所有公告
     * @return
     */
    @GetMapping("getAllAnnouncement")
    public Result getAllAnnouncement() {
        List<AnnouncementVO> announcementVOList = announcementService.getAllAnnouncement();
        return Result.success(announcementVOList);
    }

    /**
     * 添加公告
     * @param announcementDto
     * @return
     */
    @PostMapping("/addAnnouncement")
    public Result addAnnouncement(@RequestBody AnnouncementDto announcementDto) {
        announcementService.addAnnouncement(announcementDto);
        return Result.success();
    }

    @GetMapping("/deleteAnnouncement/{id}")
    public Result deleteAnnouncement(@PathVariable int id) {
        announcementService.deleteAnnouncement(id);
        return Result.success();
    }

    @PostMapping("/updateAnnouncement")
    public Result updateAnnouncement(@RequestBody AnnouncementEntity announcementEntity) {
        announcementService.updateAnnouncement(announcementEntity);
        return Result.success();
    }
}
